<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
  <head> 
    <title></title>
    <base href="<%=basePath%>">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<%@ include file="/common/importJsCss.jsp" %>
 	<script type="text/javascript" id="preJavascript">
$(function(){
    var datas = [
		{"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active"},	
		{"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active"},
		{"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active"},	
		{"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active"}		
	];
	var friends = TAFFY(datas);
	var outStr = "";
	//排序
	var orderDatas = friends().order("id").get();
	out("orderDatas",$.toJSON(orderDatas));	
	var datas = friends({city:"Seattle, WA"});
	//更新
	friends({id:2}).update({"city":"hjl"})
	out("update all",$.toJSON(friends().get()));
	//删除
	friends({id:1}).remove()
	out("delete all",$.toJSON(friends().get()));
	//总数
	var count = friends({"gender":"M"}).count();
	out("count",count);
	//插入
	friends.insert({"id":5,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active"});
	out("insert all",$.toJSON(friends().get()));
	//查找
	var results = friends({"gender":"M"}).get();
	for(var index in results){
		out("results",$.toJSON(results[index]));
	}
	var kelly = friends({id:2}).first();//$(friends({city:"Seattle, WA"}));
	out("friends({id:2}).first()",$.toJSON(kelly));
	var kellyslastname = kelly.last;
	out("kelly.last",kellyslastname);
	var cities = friends().order("id").select("id");
	$.each(cities,function(index,item){
		outStr += item+",";
	});
	out("cities",outStr);
});
	</script>
  </head>  
  <body>
	<div class="container">
        <div class="page-header">
            <h2>查询json数据库</h2>
        </div>
<pre class="prettyprint linenums"></pre>
    </div>
  </body>
</html>
